﻿using CPPEI;
using CPPEI.WebApi;
using SLG.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Ser = SLG.Domain.Services;
using Ent = SLG.Domain.Entities;

namespace SLG.WebApi.Data
{
    /// <summary>
    /// 基础数据-获得种族列表
    /// </summary>
    [AuthGetAction("BD", "GetRaces", "1.0")]
    public class GetRacesAction : BaseAction<GetRacesParams, GetRacesResult>
    {
        protected override ActionResult<GetRacesResult> OnExecute(ActionContext context, SysParameters sysParams, GetRacesParams opParams)
        {
            Ser.BDService service = new Ser.BDService();
            ListResult<Ent.BD_Race> serResult = service.GetRaces();

            if (serResult.IsSuccess)
            {
                GetRacesResult actResult = new GetRacesResult();

                for (int index = 0; index < serResult.Data.Count; index++)
                {
                    GetRacesResult.Item item = new GetRacesResult.Item();
                    item.Id = serResult.Data[index].Id;
                    item.Caption = serResult.Data[index].Caption;
                    item.ResPath = serResult.Data[index].ResPath;

                    actResult.Items.Add(item);
                }
                return new ActionResult<GetRacesResult>(actResult);
            }
            else
            {
                return new ActionResult<GetRacesResult>(serResult);
            }
        }
    }

    public class GetRacesParams
    {
    }

    public class GetRacesResult
    {
        public List<Item> Items = new List<Item>();

        public class Item
        {
            public int Id { get; set; }

            public string Caption { get; set; }

            public string ResPath { get; set; }
        }
    }
}
